package cn.hnucm.searchesservice.utils;

import java.util.Date;

/**
 * @Description: 生成一个自增的的 inter 的id
 * @author: chenjintao
 * @Date: 2021/12/22 10:50
 */
public class MyInterId {
    private Integer id;

    private static MyInterId myInterId;

    private MyInterId() {
        Date date = new Date();
        this.id = ((((date.getYear() * 12) + date.getMonth()) * 31 + date.getDate()) * 12 + date.getHours()) * 60 + date.getMinutes();
        this.id *= 10;
    }

    public static Integer getIntegerId() {
        if (myInterId == null) {
            synchronized (MyInterId.class) {
                if (myInterId == null) {
                    myInterId = new MyInterId();
                }
            }
        }
        return myInterId.id++;
    }


    public static void main(String[] args) {
        System.out.println(MyInterId.getIntegerId());
        System.out.println(MyInterId.getIntegerId());
        System.out.println(MyInterId.getIntegerId());
        System.out.println(MyInterId.getIntegerId());
        System.out.println(MyInterId.getIntegerId());
        System.out.println(MyInterId.getIntegerId());
    }
}
